Page({

	/**
	 * 页面的初始数据
	 */
	data: {
      addressData:[],
         id:0
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
    var userid = wx.getStorageSync('userid');
    var that=this;
    if (userid > 0) {
      wx.request({
        url: 'https://rjgs.sz81jk.com/api/VYwbangAPI.ashx',
        method: 'post',
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        data: {
          'action': 'getAllAddress',
          'userid': userid
        },
        dataType:JSON,
        success: function (res) {
          if (res.data != "{}")
          {
            that.setData({
              addressData: JSON.parse("[" + res.data + "]")
            })
            let address = that.data.addressData;
            for (var i = 0; i < that.data.addressData.length; i++) {
              address[i]['isSelect'] = false;
            }
            that.setData({
              addressData: address
            })
            console.log(that.data.addressData);
          }else{
            that.setData({
              addressData:null
            })
          }
        }
      })
    }
	},
  addAddress:function(){
    wx.navigateTo({
      url: '../add_edit/add_edit',
    })
  },
  editAddress:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../add_edit/add_edit?id='+id,
    })
  },
  switchSelect: function (e) {
    var index = e.currentTarget.dataset.index;
    var id = e.currentTarget.dataset.id;
    let address = this.data.addressData;
    address[index].isSelect = !address[index].isSelect;
    this.setData({
      addressData: address,
      id: id
    });
    var pages = getCurrentPages(); // 获取页面栈
    var currPage = pages[pages.length - 1]; // 当前页面
    var prevPage = pages[pages.length - 2]; // 上一个页面
    prevPage.setData({
      id: id
    });
    wx.navigateBack({
      delta: 1
    })

  },
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {
		
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
    this.onLoad();
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {
		
	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {
		
	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {
		
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
		
	}
})